package com.btex.app.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.TradeInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/5/21
 * @time 下午7:16
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class TradesAdapter extends BaseQuickAdapter<TradeInfo.DataBean.ListBean, BaseViewHolder> {
    private String mS = "";
    private String mNumber = "8";
    private String mPriceNumber = "8";
    private String mAumontNumber = "2";

    public TradesAdapter(@Nullable List<TradeInfo.DataBean.ListBean> data) {
        super(R.layout.item_trade_info, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TradeInfo.DataBean.ListBean item) {


        String num = item.getNum();
        String price = item.getPrice();
        String time = item.getTime();
        String total = item.getTotal();

        Log.i("wkehfiwuhe", mPriceNumber);

        Log.i("LKEFWLEKF", num + price + time + total);

        if (mS.equals("1")) {

            TextView item_trade_tv_time = (TextView) helper.getView(R.id.item_trade_tv_time);
            TextView item_trade_tv_number = (TextView) helper.getView(R.id.item_trade_tv_number);
            item_trade_tv_time.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.white));
            item_trade_tv_number.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.white));
//            String timedate = Tools.timedate(time);
//            item_trade_tv_time.setText(timedate);
        } else {
            helper.setText(R.id.item_trade_tv_time, time);
        }


//        helper.setText(R.id.item_trade_tv_time, item.getTime().substring(11,item.getTime().length()));
//        String trim = Tools.round(Double.valueOf(item.getNum()), 5).toString().trim();
        String s = Tools.round(Double.valueOf(item.getNum()), Integer.valueOf(mAumontNumber)).toString();
        helper.setText(R.id.item_trade_tv_number, s);

        String trim = Tools.round(Double.valueOf(item.getPrice()), Integer.valueOf(mPriceNumber)).toString().trim();

        helper.setText(R.id.item_trade_tv_price, trim);
        String trade_info = item.getTrade_info();
        Context contextObject = MyApplication.getContextObject();
        if ("buy".equals(trade_info)) {
            helper.setTextColor(R.id.item_trade_tv_price, contextObject.getResources().getColor(R.color.bg_green));
        } else {
            helper.setTextColor(R.id.item_trade_tv_price, contextObject.getResources().getColor(R.color.red));
        }


        if (time.contains("-")) {
            helper.setText(R.id.item_trade_tv_time, time);
        } else {
            String timedate = Tools.timedate(time);
            helper.setText(R.id.item_trade_tv_time, timedate);
        }
//        String timedate = Tools.timedate(time);

//        helper.setText(R.id.item_trade_price, item.getPrice());

//        helper.setText(R.id.item_trade_tv_number, item.getTotal());


    }


    public void SetTyee(String s) {

        mS = s;
    }


    public void setNumber(String number) {

        mNumber = number;
    }

    public void setPriceNumber(String PriceNumber) {

        mPriceNumber = PriceNumber;
    }

    public void setAumontNumber(String AumontNumber) {

        mAumontNumber = AumontNumber;
    }
}
